from config import DOWNLOAD_CONFIG
from crawlers.bookmark_crawler import BookmarkCrawler
from crawlers.keyword_crawler import KeywordCrawler
from crawlers.ranking_crawler import RankingCrawler
from crawlers.users_crawler import UserCrawler
from utils import checkDir

if __name__ == "__main__":

    checkDir(DOWNLOAD_CONFIG["STORE_PATH"])

    num = input("1.爬取排行榜作品\n2.爬取个人收藏\n3.爬取指定作者作品\n4.爬取含有关键词的作品\n请输入(num...):")

    if num == '1':
        # case 1: (need cookie !!!)
        #   download artworks from rankings
        #   the only parameter is flow capacity, default is 1024MB
        app = RankingCrawler(capacity=200)
        app.run()
    elif num == '2':
        # case 2: (need cookie !!!)
        #   download artworks from bookmark
        #   1st parameter is max download number, default is 200
        #   2nd parameter is flow capacity, default is 1024MB
        n_images = int(input("请输入要爬取几张:"))
        app = BookmarkCrawler(n_images, capacity=200)
        app.run()
    elif num == '3':
        # case 3: (need cookie for R18 images !!!)
        #   download artworks from a single artist
        #   2nd parameter is flow capacity, default is 1024MB
        artist_id = input("请输入要爬取的画师id:")
        app = UserCrawler(artist_id, capacity=200)
        app.run()
    elif num == '4':
        # case 4: (need premium & cookie !!!)
        #   download search results of a keyword (sorted by popularity if order=True)
        #   support advanced search, e.g. "(Lucy OR 边缘行者) AND (5000users OR 10000users)"
        #   refer to https://www.pixiv.help/hc/en-us/articles/235646387-I-would-like-to-know-how-to-search-for-content-on-pixiv-
        #   1st parameter is keyword
        #   2nd parameter is order (default is False, standing for order by date, True for order by popularity)
        #   3rd parameter is mode (support ["safe", "r18", "all"], default is "safe")
        #   4th parameter is max download number
        #   5th parameter is flow capacity
        app = KeywordCrawler(keyword="(Lucy OR 边缘行者) AND (5000users OR 10000users)",
                             order=False, mode=["safe", "r18", "all"][-1], n_images=20, capacity=200)
        app.run()
